﻿using Axios.Engine;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Dynamics.Joints;
using FarseerPhysics.Factories;
using FarseerPhysics.SamplesFramework;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace axios_tennis
{
    class Paddle : SimpleDrawableAxiosGameObject
    {
        public FixedPrismaticJoint PaddleJoint;

        public Paddle(Vector2 position)
        {
            this.Position = position;
            //this.AllowAutomaticMouseJoint = true;

        }

        public override void LoadContent(AxiosGameScreen gameScreen)
        {
            base.LoadContent(gameScreen);

            this.Texture = gameScreen.ScreenManager.Game.Content.Load<Texture2D>("paddle");
            this.Origin = new Vector2(this.Texture.Width / 2, this.Texture.Height / 2);
            this.BodyPart = BodyFactory.CreateRectangle(gameScreen.World, ConvertUnits.ToSimUnits(Texture.Width), ConvertUnits.ToSimUnits(Texture.Height), 1f);

            this.BodyPart.Position = Position;
            this.BodyPart.BodyType = BodyType.Dynamic;
            this.BodyPart.UserData = this;

            PaddleJoint = new FixedPrismaticJoint(this.BodyPart, this.BodyPart.Position, new Vector2(0, 1f));
            PaddleJoint.LowerLimit = -45f;
            PaddleJoint.UpperLimit = 45f;
            PaddleJoint.LimitEnabled = true;
            PaddleJoint.Enabled = true;
            PaddleJoint.MotorEnabled = true;
            PaddleJoint.MotorSpeed = 0.0f;
            PaddleJoint.MaxMotorForce = 1000.0f;
            gameScreen.World.AddJoint(PaddleJoint);
        }

    }
}